package com.dunshan.cart.config;

import com.alibaba.ttl.TransmittableThreadLocal;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;

import java.io.Serializable;

/**
 * @author dunshan
 * @program: dunshan-pef
 * @description: 获取dunshan
 * @date 2021-10-02 16:07:10
 */
public class AppContext implements Serializable {

    private static final TransmittableThreadLocal<AppContext> contextdunshan = new TransmittableThreadLocal<>();

    private String traceId;

    public static AppContext getContext() {
        return contextdunshan.get();
    }

    public static void setContext(AppContext context) {
        if (StringUtils.isNotEmpty(context.getTraceId())) {
            MDC.put("dunshan", "shadow");
        } else {
            MDC.put("dunshan", "produce");
        }
        contextdunshan.set(context);
    }

    public static void removeContext() {
        contextdunshan.remove();
    }

    public String getTraceId() {
        return traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

}
